<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
	<h:head>
	</h:head>
<h:body>
<h:form>
	<p:panelGrid columns="2" cellpadding="5" id="searchPanel">
		<f:facet name="header">  
        	Destination
    	</f:facet> 
		
		<h:outputLabel value="Choose your destiny: " for="locationAutoComplete"/>
		<p:autoComplete id="locationAutoComplete" 
			value="#{packageListBean.selectedLocation}" completeMethod="#{packageListBean.getLocations}"
			var="l" itemLabel="#{l.name}" itemValue="#{l}" converter="locationConverter"/>	
		
        
        <h:link outcome="home.xhtml" value="Back" />
        <f:facet name="footer">       	
			<p:commandButton update="TPpanelGroup" icon="ui-icon-search" id="confirmLocation" action="#{packageListBean.locationConfirmed()}" value="Search">
				<f:ajax render="TPpanelGroup"/>
			</p:commandButton>
         </f:facet>
    </p:panelGrid>
    
    <h:panelGroup id="TPpanelGroup">
    	<p:fieldset legend="#{packageListBean.selectedLocation.name}" rendered="#{not empty packageListBean.availableTPs}">  
    		<h:panelGrid columns="1" cellpadding="10">   
        	<h:outputText  value="#{packageListBean.selectedLocation.description}" />  
    		</h:panelGrid>  
		</p:fieldset>  
	    	<p:dataTable rendered="#{not empty packageListBean.availableTPs}" id="TPs" var="TP" value="#{packageListBean.availableTPs}"
	    		selection="#{packageListBean.selectedTP}" selectionMode="single"
	    		 rowKey="#{TP.TPId}">
	    		 <f:facet name="header">  
            	Click "View" button after selecting a package to see details  
        		</f:facet> 
	    		<p:column headerText="Travel package">
	    			#{TP.name}
	    		</p:column>
	    		<p:column headerText="Transport mean">
	    			#{TP.mean.name}
	    		</p:column>
	    		<p:column headerText="Hotel">
	    			#{TP.hotel.name}
	    		</p:column>
	    		<p:column headerText="Number of excursion">
	    			#{TP.excursions.size()}
	    		</p:column>
	    		<p:column headerText="Price per person starting from">
	    			#{TP.startingPrice.toPlainString()}
	    		</p:column>
	    		<f:facet name="footer">  
            		<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
            			action="#{packageListBean.viewTP()}" />  
        		</f:facet> 
	    	</p:dataTable>
	    <p:panel rendered="#{not empty packageListBean.error}">
	    <h:outputLabel value="#{packageListBean.error}" style="color:red" />
	    </p:panel>
    </h:panelGroup>
</h:form>
</h:body>
</html>